﻿
using System;

using MskEdit.Sdk ;
using MskEdit.Dxf.Representation ;


namespace MskEdit.Dxf.Model
{
    public class DxfStructBase
    {
        private string[]    allLines_ ;
        private SdkSubrange subrange_ ;

        
        protected delegate DxfStructBase ConstructorHandler( string[] allLines, SdkSubrange subrange ) ;
        
        
        protected static DxfStructBase TryConstruct( string[] allLines, ref int lineNo, DxfSignature signature, ConstructorHandler construct, DxfStructBase fallbackValue ) {
               
            SdkSubrange? subrange = signature.TryGetSubrange( allLines, ref lineNo, null ) ;
            if ( !subrange.HasValue )
                return fallbackValue ;
                
            return construct( allLines, subrange.Value ) ;
        }
        
        
        protected string TryFindFirstValue( string code, string fallbackValue ) {
            return DxfCodeValuePair.TryFindFirstValue( allLines_, subrange_, code, fallbackValue ) ;
        }


        protected DxfStructBase( string[] allLines, SdkSubrange subrange ) {
            allLines_ = allLines ;
            subrange_ = subrange ;
        }
        
        public string EntryType {
            get { return allLines_[subrange_.Begin + 1] ; }
        }


        public virtual string Caption {
            get { return EntryType + " " + subrange_.ToString() ; }
        }
        
    }
}
